<?php /* TASKS $Id: viewgantt.php,v 1.32.4.5 2006/11/27 14:04:13 gregorerhardt Exp $ */
global $min_view, $m, $a, $user_id, $tab, $tasks;

function php4_clone($object) {
	if (version_compare(phpversion(), '5.0') < 0) {
		return $object;
	} else {
		return @clone($object);
	}
}

$min_view = defVal( @$min_view, false);

$project_id = defVal( @$_GET['project_id'], 0);

// sdate and edate passed as unix time stamps
$sdate = dPgetParam( $_POST, 'sdate', 0 );
$edate = dPgetParam( $_POST, 'edate', 0 );
$showLabels = dPgetParam( $_POST, 'showLabels', '0' );
//if set GantChart includes user labels as captions of every GantBar
if ($showLabels!='0') {
    $showLabels='1';
}
$showWork = dPgetParam( $_POST, 'showWork', '0' );
if ($showWork!='0') {
    $showWork='1';
}
$sortByName = dPgetParam( $_POST, 'sortByName', '0' );
if ($sortByName!='0') {
    $sortByName='1';
}
$showPinned = dPgetParam( $_POST, 'showPinned', '0' );
if ($showPinned!='0') {
    $showPinned='1';
}
$showArcProjs = dPgetParam( $_POST, 'showArcProjs', '0' );
if ($showArcProjs!='0') {
    $showArcProjs='1';
}
$showHoldProjs = dPgetParam( $_POST, 'showHoldProjs', '0' );
if ($showHoldProjs!='0') {
    $showHoldProjs='1';
}
$showDynTasks = dPgetParam( $_POST, 'showDynTasks', '0' );
if ($showDynTasks != '0') {
    $showDynTasks = '1';
}
$showLowTasks = dPgetParam( $_POST, 'showLowTasks', '1' );
if ($showLowTasks != '0') {
    $showLowTasks = '1';
}


// months to scroll
$scroll_date = 1;

$display_option = dPgetParam( $_POST, 'display_option', 'this_month' );

// format dates
$df = $AppUI->getPref('SHDATEFORMAT');

if ($display_option == 'custom') {
	// custom dates
	$start_date = intval( $sdate ) ? new CDate( $sdate ) : new CDate();
	$end_date = intval( $edate ) ? new CDate( $edate ) : new CDate();
} else {
	// month
	$start_date = new CDate();
	$start_date->day = 1;
   	$end_date = new CDate($start_date);
   	$end_date->addMonths( $scroll_date );
}

// setup the title block
if (!@$min_view) {
	$titleBlock = new CTitleBlock( 'Gantt Chart' );
	$titleBlock->addButton( "view this project", 'index.php?m=projects&a=view&project_id='.$project_id );
	$titleBlock->addButton( "tasks list", 'index.php?m=tasks' );
	$titleBlock->addCell();
	$titleBlock->show();
}
?>
<script language="javascript">
function scrollPrev() {
	f = document.editFrm;
<?php
	$new_start = php4_clone($start_date);
	$new_start->day = 1;
	$new_end = php4_clone($end_date);
	$new_start->addMonths( -$scroll_date );
	$new_end->addMonths( -$scroll_date );
	echo "f.sdate.value='".$new_start->format( FMT_TIMESTAMP_DATE )."';";
	echo "f.edate.value='".$new_end->format( FMT_TIMESTAMP_DATE )."';";
?>
	document.editFrm.display_option.value = 'custom';
	f.submit()
}

function scrollNext() {
	f = document.editFrm;
<?php
	$new_start = php4_clone($start_date);
	$new_start->day = 1;
	$new_end = php4_clone($end_date);
	$new_start->addMonths( $scroll_date );
	$new_end->addMonths( $scroll_date );
	echo "f.sdate.value='" . $new_start->format( FMT_TIMESTAMP_DATE ) . "';";
	echo "f.edate.value='" . $new_end->format( FMT_TIMESTAMP_DATE ) . "';";
?>
	document.editFrm.display_option.value = 'custom';
	f.submit()
}

function showThisMonth() {
	document.editFrm.display_option.value = "this_month";
	document.editFrm.submit();
}

function showFullProject() {
	document.editFrm.display_option.value = "all";
	document.editFrm.submit();
}

Calendar.enabled = true;
</script>
<form name="editFrm" method="post" action="?<?php echo "m=$m&a=$a&tab=$tab&project_id=$project_id";?>">

<table border="0" cellpadding="3" cellspacing="0" class="infopanel" width="100%">
<input type="hidden" name="display_option" value="<?php echo $display_option;?>" />

<tr>
	<td align="center">
	<table border="0" cellpadding="0" cellspacing="3">
		<tr>
		<?php if ($display_option != "all") { ?>
			<td>
				<img src="images/prev.gif" title="<?php echo $AppUI->_( 'Previous' );?>" class="clickable" onclick="scrollPrev()">
			</td>
		<?php } ?>

			<td align="right" nowrap="nowrap">&nbsp;&nbsp;<?php echo $AppUI->_( 'From' );?></td>
			<td align="left" nowrap="nowrap">
				<input id="idDateStart" type="hidden" name="sdate" value="<?php echo $start_date->format( FMT_TIMESTAMP_DATE );?>" />
				<input id="idDateStartD" type="text" class="text" name="show_sdate" value="<?php echo $start_date->format( $df );?>" size="12" disabled="disabled" />
				<img id="idDateStartB" class="ico clickable" src="images/calendar.gif"/>
			</td>

			<td align="right" nowrap="nowrap">&nbsp;&nbsp;<?php echo $AppUI->_( ' to ' );?></td>
			<td align="left" nowrap="nowrap">
				<input id="idDateEnd" type="hidden" name="edate" value="<?php echo $end_date->format( FMT_TIMESTAMP_DATE );?>" />
				<input id="idDateEndD" type="text" class="text" name="show_edate" value="<?php echo $end_date->format( $df );?>" size="12" disabled="disabled" />
				<img id="idDateEndB" class="ico clickable" src="images/calendar.gif"/>&nbsp;
			</td>
		<?php if ($display_option != "all") { ?>
			<td>
			  	<img src="images/next.gif" title="<?php echo $AppUI->_( 'Next' );?>" class="clickable" onclick="scrollNext()">
			</td>
		<?php } ?>
		</tr>
	</table>
	</td>
</tr>
<tr>
	<td colspan="100%" align="center">
	<table border="0" cellpadding="0" cellspacing="2">
		<tr>
			<td>
				<input type="checkbox" name="showLabels" <?php echo (($showLabels==1) ? "checked=true" : "");?>>
			</td>
			<td><?php echo $AppUI->_( 'Show captions' );?>
			</td>
			<td>
				<input type="checkbox" name="showWork" <?php echo (($showWork==1) ? "checked=true" : "");?>>
			</td>
			<td>
				<?php echo $AppUI->_( 'Show work instead of duration' );?>
			</td>
			<td>
				<input type="checkbox" name="sortByName" <?php echo (($sortByName==1) ? "checked=true" : "");?>>
			</td>
			<td>
				<?php echo $AppUI->_( 'Sort by Task Name' );?>
			</td>
			<td>
				<input type="button" class="button" value="<?php echo $AppUI->_( 'submit' );?>" onclick='document.editFrm.display_option.value="custom";submit();'>
			</td>
		</tr>
	</table>
	</td>
</tr>
<?php if($a == 'todo') { ?>
<tr>
	<td align="center" nowrap="nowrap" colspan="100%">
		<table border="0" cellpadding="0" cellspacing="2">
		<tr>
			<td align="center">
				<input id="idShowPinned" type="checkbox" name="showPinned" <?php echo $showPinned ? 'checked="checked"' : ""; ?> />
			</td>
			<td><label for="idShowPinned"><?php echo $AppUI->_('Pinned Only'); ?></label></td>
			<td align="center">
				<input id="idShowArcProjs" type="checkbox" name="showArcProjs" <?php echo $showArcProjs ? 'checked="checked"' : ""; ?> />
			</td>
			<td><label for="idShowArcProjs"><?php echo $AppUI->_('Archived Projects'); ?></label></td>
			<td>
				<input id="idShowHoldProjs" type="checkbox" name="showHoldProjs" <?php echo $showHoldProjs ? 'checked="checked"' : ""; ?> />
			</td>
			<td><label for="idShowHoldProjs"><?php echo $AppUI->_('Projects on Hold'); ?></label></td>
			<td>
				<input id="idShowDynTasks" type="checkbox" name="showDynTasks" <?php echo $showDynTasks ? 'checked="checked"' : ""; ?> />
			</td>
			<td><label for="idShowDynTasks"><?php echo $AppUI->_('Dynamic Tasks'); ?></label></td>
			<td>
				<input id="idShowLowTasks" type=checkbox name="showLowTasks" <?php echo $showLowTasks ? 'checked="checked"' : ""; ?> />
			</td>
			<td><label for="idShowLowTasks"><?php echo $AppUI->_('Low Priority Tasks'); ?></td>
			</tr>
		</table>
	</td>
</tr>
<?php } ?>
</form>

<tr>
	<td align="center" valign="bottom" colspan="7">
		<?php echo "<a href='javascript:showThisMonth()'>".$AppUI->_('show this month')."</a> : <a href='javascript:showFullProject()'>".($a == 'todo' ? $AppUI->_('show all') : $AppUI->_('show full project'))."</a><br>"; ?>
	</td>
</tr>

</table>

<table cellspacing="0" cellpadding="0" border="0" width="100%" class="subinfopanel">
<tr style="background-color: white">
	<td class="internal">
		<div style="overflow: auto; width: 100%; height: 300px; padding: 0px; margin: 0px; virtical-align: top" align="center">
<?php
if ($a != 'todo') {
	$q = new DBQuery;
	$q->addTable('tasks');
	$q->addQuery('COUNT(*) AS N');
	$q->addWhere("task_project=$project_id");
	$cnt = $q->loadList();
	$q->clear();
} else {
	if (empty($tasks))
		$cnt[0]['N'] = 0;
	else
		$cnt[0]['N'] = 1;
}
if ($cnt[0]['N'] > 0) {
	$src =
	  "?m=tasks&a=gantt&suppressHeaders=1&project_id=$project_id" .
	  ( $display_option == 'all' ? '' :
		'&start_date=' . $start_date->format( "%Y-%m-%d" ) . '&end_date=' . $end_date->format( "%Y-%m-%d" ) ) .
	  "&width=' + ((navigator.appName=='Netscape'?window.innerWidth:document.body.offsetWidth)-150) + '&showLabels=".$showLabels."&showWork=".$showWork."&sortByName=".$sortByName.'&showPinned='.$showPinned.'&showArcProjs='.$showArcProjs.'&showHoldProjs='.$showHoldProjs.'&showDynTasks='.$showDynTasks.'&showLowTasks='.$showLowTasks.'&caller='.$a.'&user_id='.$user_id;

	echo "<script>document.write('<img src=\"$src\">')</script>";
} else {
	echo $AppUI->_( "No tasks to display" );
}
?>
		</div>
	</td>
</tr>
</table>
<br/>
